package com.sgy.sgylearningproject.mybatis.order_user.mapper;

import com.sgy.sgylearningproject.mybatis.order_user.pojo.Order;
import com.sgy.sgylearningproject.mybatis.order_user.pojo.User;
import com.sgy.sgylearningproject.mybatis.usertest.dao.UserMapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Administrator
 * @date 2025/7/2 22:47
 * @description
 */
public interface IOrderMapper {

    // 查询订单的同时还查询该订单所属用户信息
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "orderTime", column = "ordertime"),
            @Result(property = "total", column = "total"),
            @Result(property = "user", column = "uid", javaType = User.class,
                    one = @One(select = "com.sgy.sgylearningproject.mybatis.order_user.mapper.IUserMapper.findUserById"))
    })
    @Select("select * from orders")
    public List<Order> findOrderAndUser();

    @Select("select * from orders where uid = #{uid}")
    public List<Order> findOrderByUid(int uid);
}
